﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PJRScrum
{
    public partial class NewImportGui : Form
    {
        enum CurrentPanel
        {
            StadKiezen,
            PlattegrondKiezen,
            WinkelBouwen,
            Opslaan,
        }
        CurrentPanel currentPanelType = CurrentPanel.StadKiezen;
        ImportGuiPanel currentPanel;
        List<ImportGuiPanel> panels = new List<ImportGuiPanel>()
        {
            new ImportGuiPanelOne(),
            new ImportGuiPanelTwo(),
            new ImportGuiPanelThree(),
            new ImportGuiPanelFour()
        };
        NextPreviousPanel nextPreviousPanel = new NextPreviousPanel();

        #region Benodigde info fields
        string stadsNaam;
        Image plattegrondImage;

        #endregion
        public NewImportGui()
        {
            InitializeComponent();
            nextPreviousPanel.Next += new EventHandler(nextPreviousPanel_Next);
            nextPreviousPanel.Previous += new EventHandler(nextPreviousPanel_Previous);
            nextPreviousPanel.Cancel += new EventHandler(nextPreviousPanel_Cancel);
            currentPanel = panels[(int)currentPanelType];
            Controls.Add(currentPanel);
            nextPreviousPanel.Location = new Point(0, panels[(int)currentPanelType].Height);
            Controls.Add(nextPreviousPanel);
            Height = SystemInformation.CaptionHeight + 15 + panels[0].Height + nextPreviousPanel.Height;
        }

        void nextPreviousPanel_Previous(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }

        void nextPreviousPanel_Next(object sender, EventArgs e)
        {
            if (currentPanel.Finished)
            {
                switch (currentPanelType)
                {
                    case CurrentPanel.StadKiezen:
                        stadsNaam = (currentPanel as ImportGuiPanelOne).GetStadsNaam();
                        break;
                    case CurrentPanel.PlattegrondKiezen:
                        plattegrondImage = (currentPanel as ImportGuiPanelTwo).GetImage();
                        (panels[(int)CurrentPanel.WinkelBouwen] as ImportGuiPanelThree).SetImage(plattegrondImage);
                        (panels[(int)CurrentPanel.WinkelBouwen] as ImportGuiPanelThree).Redraw();
                        break;
                    case CurrentPanel.WinkelBouwen:
                        nextPreviousPanel.BtnNext.Text = "Finished";
                        Bitmap b = (panels[(int)CurrentPanel.PlattegrondKiezen] as ImportGuiPanelTwo).GetImage() as Bitmap;
                        View.GetInstance().Plattegrond = b;
                        View.GetInstance().SlaAfbeeldingOp(b);
                        break;
                    case CurrentPanel.Opslaan:
                        if (!(currentPanel as ImportGuiPanelFour).Opgeslagen)
                        {
                            if (MessageBox.Show("Weet u zeker dat u de wizard wilt afsluiten zonder op te slaan?", "Afsluiten", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
                                return;
                        }
                        this.Close();
                        return;
                    default:
                        return;
                }
                Controls.Remove(currentPanel);
                currentPanel = panels[(int)++currentPanelType];
                Controls.Add(currentPanel);
            }
            else
            {
                MessageBox.Show("U heeft nog niet alles ingevuld.");
            }
        }

        void nextPreviousPanel_Cancel(object sender, EventArgs e)
        {
            if (MessageBox.Show("Weet u zeker dat u de wizard wilt afsluiten?", "Afsluiten", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                this.Close();
        }
    }
}
